﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using Agresso.Interface.Layer.Service;
using Agresso.Interface.Layer.Gateway;

namespace Agresso.Interface.Layer.Web
{
    public class ServiceFactory
    {
        Hashtable m_userControlCollection = new Hashtable();
        DataBaseConnectivity m_dataBaseConectivity;

        static volatile ServiceFactory m_instance;
        public const string USERSERVICE = "USER_SERVICE";
        public const string ALERT_SERVICE = "ALERT_SERVICE";

        public ServiceFactory()
        {
            m_dataBaseConectivity = new DataBaseConnectivity();
        }
        public static ServiceFactory Instance()
        {
            if (m_instance == null)
            {
                m_instance = new ServiceFactory();
            }
            return m_instance;
        }
        public IService GetService(string key)
        {
            IService svc = (IService)m_userControlCollection[key];
            if (svc == null)
            {
                switch (key)
                {
                    case USERSERVICE:
                        m_userControlCollection.Add(key, new UserService());
                        break;
                    case ALERT_SERVICE:
                        m_userControlCollection.Add(key, new AlertService());
                        break;
                }
            }
            svc = (IService)m_userControlCollection[key];
            return svc;
        }
    }
}